package cn.edu.nuc.crm.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.nuc.crm.dto.PageInfo;
import cn.edu.nuc.crm.entity.Application;
import cn.edu.nuc.crm.entity.Repayment;
import cn.edu.nuc.crm.service.interfaces.RepaymentService;

@Controller
public class RepaymentController {
	@Autowired
	private RepaymentService repaymentService;
	
	@RequestMapping(value="/repaymentlist",method=RequestMethod.GET)
	public String select(@RequestParam(name="current",defaultValue="1") int current,
			HttpSession session, Model model){	
		try {
			PageInfo pi = repaymentService.pi(current);
			session.setAttribute("pi", pi);	
			
			return "repayment/repaymentlist";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "redirect:login";
	}
	/**
	 * 查询
	 * @return
	 */
	@RequestMapping(value="/repaymentsearch",method=RequestMethod.POST)
	public String search(Model model,String accountTruename){
		if( accountTruename != null && !accountTruename.equals("") ){
			List<Repayment> list = repaymentService.selectByName(accountTruename);
			model.addAttribute("list", list);
			return "repayment/search";
		}
		return "redirect:repayment/repaymentlist";	
	}
	/**
	 * 编辑
	 * @return
	 */
	
	 @RequestMapping(value="/repaymentedit",method=RequestMethod.GET)
	public String update(Integer repaymentId,HttpSession session){
		 Repayment repayment=repaymentService.selectByPrimaryKey(repaymentId);
		session.setAttribute("item",repayment);
		return "repayment/edit";
		
	}
	 /**
		 * 删除申请
		 * @return
		 */
		@RequestMapping(value="/repaymentdelete",method=RequestMethod.GET)
		public String delete(Integer repaymentId,HttpSession session){
			int result=repaymentService.deleteByPrimaryKey(repaymentId);
			if(result>0){	
				return "/success1";	
			}else{
				session.setAttribute("info", "该产品不能删除");
				return "/productlist";
			}
		}
		
		
	
	
	
}
